package proyecto.testcasetool.provider.scenarios;

import java.util.Collection;

import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;

import proyecto.testcasetool.TestcasetoolPackage;
import proyecto.testcasetool.UseCase;
import proyecto.testcasetool.provider.UseCaseItemProvider;

public class UseCaseItemProviderScenarios extends UseCaseItemProvider {

	protected Collection children = null;
	protected AlternativesGhostItemProvider alternativesItemProvider = null;
	
	public UseCaseItemProviderScenarios(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}
	
	@Override
	public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) {
		if (childrenFeatures == null) {
			super.getChildrenFeatures(object);
			childrenFeatures.remove(TestcasetoolPackage.Literals.USE_CASE__ALTERNATIVE_FLOW);
			//childrenFeatures.remove(TestcasetoolPackage.Literals.USE_CASE__POS_CONDITION);
			//childrenFeatures.remove(TestcasetoolPackage.Literals.USE_CASE__PRE_CONDITION);
		}
		return childrenFeatures;
	}

	@Override
	public Collection<?> getChildren(Object object) {
		UseCase useCase = (UseCase) object;
		if (children == null) {
			children = super.getChildren(object);
			this.alternativesItemProvider = new AlternativesGhostItemProvider(adapterFactory, useCase);
			children.add(this.alternativesItemProvider);
		}
		return children;
		
	}
	
	/**
	 * No permite borrar el basicScenario del caso de uso
	 */
	@Override
	protected Command createSetCommand(EditingDomain domain, EObject owner,
			EStructuralFeature feature, Object value) {
		return UnexecutableCommand.INSTANCE;
	}
	
	
	public Object getAlternatives() {
		return this.alternativesItemProvider;
	}
	
	/**
	 * Disposes the non-modeled children.
	 */
	@Override
	public void dispose() {
		super.dispose();
		if (children != null) {
			alternativesItemProvider.dispose();
		}
	}
}
